﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Deflection
{
    class PlayerBasicProjectile : Projectile
    {
        public ParticleSystem particleSystem;
        public Color color;
        public float scale;
        public PlayerBasicProjectile(Vector2 position, Vector2 direction, Color color, Player player) : base(position, direction)
        {
            this.color = color;
            scale = 0.15f;
            sizeInPixels = new Vector2(scale * Player.PlayerSprite.Bounds.Width, scale * Player.PlayerSprite.Bounds.Height);
            particleSystem = new ParticleSystem(this.position, Player.PlayerSprite, this.color, scale/3);
            this.player = player;
            particleSystem.MaximumParticles = 40;
            particleSystem.MaxLife = 10;
            particleSystem.SpawnRate = 0;
            particleSystem.minParticleVelocity = -1;
            particleSystem.maxParticleVelocity = 2;
            state = ObjectState.Alive;
        }


        public override void Update(GameTime gameTime)
        {
            switch (state)
            {
                case ObjectState.Alive:
                    particleSystem.Position = this.position;
                    particleSystem.Update(gameTime);
                    break;
                case ObjectState.Dying:
                    this.IsCollidable = false;
                    if (particleSystem.Particles.Count > 0)
                    {
                        particleSystem.Position = this.position;
                        particleSystem.Update(gameTime);
                        particleSystem.Spawning = false;
                    }
                    else
                    {
                        state = ObjectState.Dead;
                    }
                    break;
                case ObjectState.Dead:
                    this.Die();
                    break;
                default:
                    break;
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            switch (state)
            {
                case ObjectState.Alive:
                    spriteBatch.Draw(Player.PlayerSprite, position, null, color, 0, new Vector2(Player.PlayerSprite.Bounds.Center.X, Player.PlayerSprite.Bounds.Center.Y), scale, SpriteEffects.None, 0);
                    particleSystem.Draw(gameTime, spriteBatch);
                break;
                case ObjectState.Dying:
                    particleSystem.Draw(gameTime, spriteBatch);
                break;
                case ObjectState.Dead:
                break;
                default:
                break;
            }
        }
    }
}
